/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package upeu.cepre.business;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import upeu.cepre.model.Periodo;

import upeu.cepre.util.DataBaseConexion;

/**
 *
 * @author Elvis Zanguetsu
 */
public class PeriodoManager {

    public Connection connection;

    public List<Periodo> Report() {

        List<Periodo> periodos = new ArrayList<Periodo>();
        Periodo periodo = new Periodo();
        try {

            connection = DataBaseConexion.getConexion();
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("select * from periodo");
            while (rs.next()) {

                periodo.setIdPeriodo(rs.getString("idPeriodo"));
                periodo.setAño(rs.getString("año"));
                periodo.setNumPeriodo(rs.getString("numPeriodo"));
                periodo.setCostoMatricula(rs.getString("costoMatricula"));
                periodo.setCostoEducacion(rs.getString("costoEducacion"));
                periodo.setCostoIngreso(rs.getString("costoIngreso"));
                periodo.setCuotas(rs.getString("cuotas"));


                periodos.add(periodo);
            }
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return periodos;
    }

    public Periodo finByIdPeriodo(String idperiodo) {
        Periodo periodo = new Periodo();


        try {
            Connection connection;
            connection = DataBaseConexion.getConexion();
            PreparedStatement preparedStatement = connection.prepareStatement("select * from periodo where idPeriodo=?");
            preparedStatement.setString(1, idperiodo);
            ResultSet rs = preparedStatement.executeQuery();

            if (rs.next()) {
                periodo.setIdPeriodo(rs.getString("idPeriodo"));
                periodo.setAño(rs.getString("año"));
                periodo.setNumPeriodo(rs.getString("numPeriodo"));
                periodo.setCostoMatricula(rs.getString("costoMatricula"));
                periodo.setCostoEducacion(rs.getString("costoEducacion"));
                periodo.setCostoIngreso(rs.getString("costoIngreso"));
                periodo.setCuotas(rs.getString("cuotas"));

            }

            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return periodo;
    }
}
